package com.jinyijia.api.rest.v1.shippingaddress.dto;


import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;

/**
 * @author WX
 * @date 2018/8/16
 **/
@Data
@NoArgsConstructor
public class ReceivingInformationDTO {

    private Integer id;
    private String name;

    private String mobile;
    private String province;

    private String city;

    private String district;

    private String town;

    private Integer userId;

    private String road;

    private Boolean enabled;

    /**
     * 由于android前台页面传过来的数据格式为:
     * "enabled":true,
     * "name":"张三",
     * "phone":"17863073100",
     * "region":"山东省-济南市-天桥区",
     * "address":"凤凰山商贸城B区"
     * region只有三级,没有(办事处/镇)这个字段,所以this.town = "";
     */
    public ReceivingInformationDTO(ShippingAddressDTO shippingAddressDTO) {
        this.name = shippingAddressDTO.getName();
        this.mobile = shippingAddressDTO.getPhone();
        if (StringUtils.isNotBlank(shippingAddressDTO.getRegion())) {
            String[] address = shippingAddressDTO.getRegion().split("-");
            this.province = address[0];
            this.city = address[1];
            this.district = address[2];
            this.town = "";
        } else {
            this.province = "";
            this.city = "";
            this.district = "";
            this.town = "";
        }
        this.road = shippingAddressDTO.getAddress();
        this.enabled = shippingAddressDTO.getEnabled();
    }

}
